def prime(x):
    if x == 1:
        return False
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


a = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}
s = [x for x in input().split()]
f = ''
flag = True
if len(s) < 3:
    print('Wrong input')
    flag = False
for i in range(len(s)):
    if s[i] not in a and flag is True:
        print('Wrong input')
        flag = False
if flag is True:
    for i in s:
        f += a[i]
    f = int(f)
    if f < 100 or f > 999:
        flag = False
        print('Wrong input')
    d, g = 0, 0
    for i in range(f, 100, -1):
        if prime(i):
            d = i
            break
    for i in range(f, 1000):
        if prime(i):
            g = i
            break
    if flag is True:
        if (f - d) > (g - f):
            print(g)
        else:
            print(d)




